package cn.sundat.utils;

import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

public class ThumbImgUtils {
	
	public static void slt(String oldimg,String newimg) {
		 try {  
	            File fi = new File(oldimg); //大图文件  
	            File fo = new File(newimg); //将要转换出的小图文件  
	            int nw = 500;  
	            AffineTransform transform = new AffineTransform();  
	            BufferedImage bis = ImageIO.read(fi); //读取图片  
	            int w = bis.getWidth();  
	            int h = bis.getHeight();  
	            int nh = (nw*h)/w ;  
	            double sx = (double)nw/w;  
	            double sy = (double)nh/h;  
	            transform.setToScale(sx,sy);   
	            System.out.println(w + " " +h);  
	            
	            AffineTransformOp ato = new AffineTransformOp(transform,null);  
	            BufferedImage bid = new BufferedImage(nw,nh,BufferedImage.TYPE_3BYTE_BGR);  
	            ato.filter(bis,bid);  
	            ImageIO.write(bid,"jpeg",fo);  
	        } catch(Exception e) {  
	            e.printStackTrace();  
	        }  
	}
}
